package cn.edu.hhu.DAO.impl;

import cn.edu.hhu.Bean.Course;
import cn.edu.hhu.DAO.CourseDao;
import cn.edu.hhu.util.JDBCUtils;
import org.junit.Test;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;
import java.util.Map;

/**
 * @anthor: lddd
 * @date: 2020/5/9 - 22:47
 * @description:
 **/
public class CourseDaoImpl implements CourseDao {
    JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());

    /**
     * 通过学号查询课程列表
     * @return 课程列表
     */
    @Override
    public List<Course> queryCourseBySid(String sid) {
        String sql = "SELECT * FROM view_student_course_teacher WHERE sid = ?";
        List<Course> list = template.query(sql, new BeanPropertyRowMapper<>(Course.class), sid);
        return list;
    }
    @Test
    public void test(){
        CourseDaoImpl courseDao = new CourseDaoImpl();
        List<Course> courses = courseDao.queryCourseBySid("555");
        System.out.println(courses.size());
        for (Course cours : courses) {
            System.out.println(cours);
        }
    }
}
